package com.rasenhund.android.grecorder.helper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.rasenhund.android.grecorder.dao.RecordDao;

/**
 * データベース作成用Helperクラス
 */
public class DbHelper extends SQLiteOpenHelper{
    
    private static final String DATABASE_NAME = "senjou_db";
    private static final int DATABASE_VERSION = 1;
    
    // TODO: テーブル定義が変わった場合はここを修正
    private static final String CREATE_TABLE = 
        "create table " + RecordDao.TABLE_NAME + 
        "(" + 
        RecordDao.Columns.ROW_ID +  " integer primary key autoincrement" + 
        ", " + RecordDao.Columns.STAGE_CD + " integer default 0" + 
        ", " + RecordDao.Columns.CATEGORY_CD + " integer default 0" + 
        ", " + RecordDao.Columns.RESULT_CD + " integer default 0" + 
        ", " + RecordDao.Columns.INSERT_DATE + " text" + 
        ")";
    
//  ", " + RecordDao.Columns.TIMESTAMP + " timestamp default datetime() + "
    
    private static final String DROP_TABLE = 
        "drop table if exists " + RecordDao.TABLE_NAME;
    
    public DbHelper(Context context){
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(DROP_TABLE);
        db.execSQL(CREATE_TABLE);
    }
}
